1. Technical Field
The present invention relates generally to computer systems and, in particular, to a method and system for caching across multiple contexts in a computer system.
2. Background Description
A context is a scope in which variables and/or keys are resolved to specific values. The contexts could represent transactions. Alternatively, they could represent different procedure invocations. Programming languages such as C, C++, Java, and Pascal, among others, may create multiple contexts. Two contexts might have variables of the same name but with different values within the different contexts. For example, suppose that the main body of a C program has a variable x. The main program calls a function foo which has a local variable x. When foo is called from the main program, this creates a new context. The value of x within the context of the function foo may be different from the value for x within the context of the main program. A context may also represent a transactional context. A transaction is a series of operations applied to a set of objects in a manner that transforms the system from one consistent state to another consistent state. Transactional contexts isolate the effects of transactions such that concurrently executing transactions do not interfere with each other; such interference, in general, leads to data inconsistencies.
Accordingly, it would be desirable and highly advantageous to have a method and system for caching across multiple contexts in a computer system. It would also be desirable and highly advantageous for such a method and system to maintain data consistency.
The problems stated above, as well as other related problems of the prior art, are solved by the present invention, a method and system for caching across multiple contexts in a computer system.
According to a first aspect of the invention, in a system that includes a plurality of objects and at least one cache, wherein each object has a key associated therewith and is capable of having different values for at least two of a plurality of different contexts, a method for caching at least some of the plurality of objects is provided. The method includes the step of maintaining a cache directory structure in which at least two different values are capable of being associated with at least one of the plurality of objects, each of the at least two different values corresponding to a different context. An object to be cached is identified from among the plurality of objects and also a context from among the plurality of different contexts. The identified object is stored in the at least one cache based upon the key associated therewith and the identified context.
According to a second aspect of the invention, the at least one cache maintains at least a portion of a data structure for storing multiple versions of the identified object and said storing step further includes the step of identifying the at least a portion of the data structure from the key associated with the identified object.
According to a third aspect of the invention, the storing step further includes the steps of generating a composite index from the key associated with the identified object and the identified context, and storing the identified object based upon the composite index.
According to a fourth aspect of the invention, the method further includes the step of looking up a given object from among the plurality of objects based upon a key associated with the given object and one of the plurality of different contexts.
According to a fifth aspect of the invention, the method further comprises the step of deleting a cached object based upon a key associated with the cached object and one of the plurality of different contexts.
According to a sixth aspect of the invention, the method further includes the steps of maintaining a data structure that includes at least one key associated with at least one given object from among the plurality of objects, the at least one given object being cached within one of the plurality of different contexts; and deleting the at least given object by identifying the at least one object in the data structure based upon the at least one key associated therewith.
According to a seventh aspect of the invention, the method further includes the step of copying at least one given object from among the plurality of objects that is cached under one of the plurality of contexts to another one of the plurality of contexts.
According to an eighth aspect of the invention, the plurality of different contexts represent transactional contexts.
According to a ninth aspect of the invention, cached objects represent query results.
According to a tenth aspect of the invention, in a system that includes at least one object capable of having a plurality of values within a plurality of different contexts, a method for propagating at least one of the plurality of values among the plurality of different contexts is provided. The method includes the step of maintaining at least one dependency between the at least one object and underlying data. The at least one of the plurality of values is identified for the at least one object within a context from among the plurality of contexts. The at least one of the plurality of values is propagated to at least one other context from among the is plurality of contexts. The at least one object has identical dependencies in the context and the at least one other context.
According to an eleventh aspect of the invention the underlying data is dependent underlying data, and at least some of the plurality of values are derived from the dependent underlying data.
According to a twelfth aspect of the invention, the underlying data is dependent underlying data, and at least some of the plurality of values are query results derived from the dependent underlying data.
According to a thirteenth aspect of the invention, the plurality of different contexts are transactional contexts.
According to a fourteenth aspect of the invention, cached objects are query results and the plurality of different contexts are transactional contexts.
According to a fifteenth aspect of the invention, in a system that includes at least one object capable of having a plurality of values within a plurality of different contexts, wherein a value from among the plurality of values of the at least one object depends on underlying data, a method for maintaining dependencies between the at least one object and the underlying data when effects from a context among the plurality of contexts are realized within at least one other context among the plurality of contexts is provided. The method includes the step of recording at least one event that occurs with the context, wherein the at least one event is capable of affecting dependencies between the at least one object and the underlying data within the at least one other context. Within the at least one other context, changes are realized to the underlying data performed under the context. Also within the at least one other context, the at least one event recorded within the context is replayed.
According to a sixteenth aspect of the invention, the plurality of contexts are transactional contexts and the realizing step includes the step of committing the context as a transactional context.
According to a seventeenth aspect of the invention, a computer system is provided. The computer system includes at least one client, at least one server, a cache adapted to allow multiple copies of a same object to be cached under different contexts, and a context manager adapted to manage the different contexts.
According to an eighteenth aspect of the invention, the context manager is a transaction manager.
According to a nineteenth aspect of the invention, the context manager is a transaction manager adapted to support lock-based, pessimistic concurrency control.
According to a twentieth aspect of the invention, the context manager is a transaction manager adapted to support optimistic concurrency control.
These and other aspects, features and advantages of the present invention will become apparent from the following detailed description of preferred embodiments, which is to be read in connection with the accompanying drawings.